package com.expressage.controller;

import com.expressage.po.CheckRecord;
import com.expressage.po.Salary;
import com.expressage.service.CheckRecordService;
import com.expressage.vo.CheckrecordVo;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class CheckRecordController {
    @Autowired
    CheckRecordService checkRecordService;
    Logger logger = Logger.getLogger(CheckRecordController.class);

    @RequestMapping("jspafter/checkrecordlist")
    public String findAll(Model model){
        logger.info("进入考勤列表控制器");
        List<CheckrecordVo> list = checkRecordService.findAll();
        model.addAttribute("checkrecordlist",list);
        logger.info(list);
        return "jspafter/checkrecordlist";
    }
    @RequestMapping("jspafter/checkrecordlistone")
    public String findByid(int salaryid,Model model){
        logger.info("查询单个考情对象");
        CheckRecord checkRecord = checkRecordService.findByid(salaryid);
        model.addAttribute(checkRecord);
        logger.info(checkRecord);
        return "jspafter/checkrecordlistone";
    }

    @RequestMapping("jspafter/toaddcheckrecord")
    public String toadd(){
        logger.info("去添加考勤记录");
        return "jspafter/addcheckrecord";
    }

    @RequestMapping("jspafter/addcheckrecord")
    public String add(CheckRecord checkRecord){
        logger.info("添加考勤记录中 ");
       boolean flag = checkRecordService.add(checkRecord);
       logger.info(flag);
       return "redirect:checkrecordlist.action";
    }

    @RequestMapping("jspafter/toupdatecheckrecord")
    public String toupdate(){
        logger.info("去修改考勤对象");

        return "jspafter/toupdatecheckrecord";
    }

    @RequestMapping("jspafter/updatecheckrecord")
    public String update(CheckRecord checkrecord){
        logger.info("进入修改考勤表");
        boolean flag = checkRecordService.update(checkrecord);
        logger.info(flag);
        return "redirect:checkrecordlist.action";
    }
    @RequestMapping("jspafter/deletecheckrecord")
    public String delete(int[] array){
        logger.info("进入删除考情对象控制器");
        if(array.length>0){
            boolean falg = checkRecordService.delete(array);
            logger.info(falg?true:false);
        }
        return "redirect:checkrecordlist.action";
    }
}
